package com.ymatou.app.testcase;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.parameter.ProductListBean;
import com.ymatou.app.service.ProductListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.BuyerCallService;
import com.ymttest.business.service.SellerCallService;

public class Ts_ProductList {
	
	private static ProductListBean listBean = null;
	private static ProductListCall listCall = null;
	private static BuyerCallService buyerCallService = null;
	private static SellerCallService sellerCallService = null;
	private int activityId = 0;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商品列表接口");
		buyerCallService = new BuyerCallService("ukseller", "aabbcc");
		sellerCallService = new SellerCallService("ukseller", "aabbcc");
	}

	@Before
	public void caseUp() {
		listCall = new ProductListCall();
		listBean = new ProductListBean();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(listCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ProductList_001() {
		Logger.start(true,"验证直播商品数量");
		try {
			Logger.comment("直播验证");
			JSONArray productIds = buyerCallService.getProductIdsInProgress();
			String query_str = "";
			for (int i = 0; i < productIds.length(); i++) {
				query_str += "productids[]=" + productIds.getString(i) + "&";
			}
			
			listCall.setData(query_str);
			listCall.callService();			
			Logger.comment("activityCall send:" + listCall.getEntityString());
			Logger.comment("activityCall response:" + listCall.getReturnData());
			
			Logger.verifyEquals(3, listCall.getList().length(), "验证直播商品数量");
			
			activityId = sellerCallService.getActivityInProgress();
			sellerCallService.closeActivity(activityId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
